<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/11/22 0022
 * Time: 上午 8:33
 */
header("content-type:text/html;charset=utf-8");
$all_data = array(
    1 => array('学PHP，冲击月薪10000+你也可以！','……'),
    2 => array('传智播客PHP项目答辩，群雄竞技牛人辈出','……'),
    3 => array('夏“超”激情，Ajax公开课与你相约','……'),
    4 => array('学PHP编程，不做孬种程序员！','……'),
);
$id = isset($_GET['id'])? intval($_GET['id']) : 1;
$id_prev = $id - 1;
$id_next = $id + 1;
if($id < 1) $id = 1;
if($id > 4) $id = 4;
if($id_prev < 1) $id_prev = 1;
if($id_next > 4) $id_next = 4;
if(isset($_COOKIE['history'])){
    $cookie_arr = explode(',',$_COOKIE['history'],4);
    foreach($cookie_arr as $k=>$v){
        $cookie_arr[$k] = intval($cookie_arr[$k]);
        if($v == $id) unset($cookie_arr[$k]);
    }
    if(count($cookie_arr)>3){
        array_shift($cookie_arr);
    }
    $cookie_arr[] = $id;
    setcookie('history',implode(',',$cookie_arr));
}else{
    $cookie_arr = array($id);
    setcookie('history',$id);
}
if(isset($_GET['action'])){
    if($_GET['action'] == 'clear'){
        $cookie_arr = array();
        setcookie('history','',time()-1);
    }
}
$data = $all_data[$id];
$data_history = array();
foreach($cookie_arr as $v){
    if(isset($all_data[$v])){
        $data_history[$v] = $all_data[$v][0];
    }
}
define('APP','itcast');
require('article_html.php');